Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.4k Golang : Get local time and equivalent time in different time zone
+11.9k Golang : Save webcamera frames to video file
+9.1k Golang : Generate random Chinese, Japanese, Korean and other runes
+8.3k Golang : How to check variable or object type during runtime?
+5.2k Python : Delay with time.sleep() function example
+10.3k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+10.1k Golang : Convert file unix timestamp to UTC time example
+28.5k Golang : Detect (OS) Operating System
+5.3k Golang : If else example and common mistake
+14.8k Golang : package is not in GOROOT during compilation
+6.3k PHP : Shuffle to display different content or advertisement
+12.1k Golang : Get month name from date example